from flask import Flask
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
# print(common.config)
# import backend.data_base.models
app = Flask(__name__)
# 配置数据库
app.config.from_object('common.config')
# app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/test_backend_17'
# app.config["SECRET_KEY"] = "SECRET_KEY"
# app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# app.config["SQLALCHEMY_POOL_SIZE"] = 100
# 将flask实例加载到 flask_restful
# print(app.config)
api = Api(app)
db = SQLAlchemy(app)
# 使用 CROS 解决同源问题，同IP，端口，协议
CORS(app)

def router():
    from api.testcase import TestCaseAdd, TestCaseGet, TestCaseDelete, TestCaseUpdate
    api.add_resource(TestCaseAdd, "/testcase/add")
    api.add_resource(TestCaseGet, "/testcase/get")
    api.add_resource(TestCaseDelete, "/testcase/delete")
    api.add_resource(TestCaseUpdate, "/testcase/update")

    from api.user import Login, Register
    api.add_resource(Login, "/user/login")
    api.add_resource(Register, "/user/register")


# 快捷提示输入自动补全，自定义
if __name__ == '__main__':
    # mysql = r"start D:\cqz\tests\02接口测试\工具\API_Server\1.启动MySQL.bat"
    # import os
    # os.system(mysql)
    router()
    # app.run(debug=False, processes=True)
    # app.run(threaded=True)
    app.run(debug=True)
    # app.run(processes=4)